class RankView extends zysx.BaseView{
     private btn_back:eui.Image
	 private list:eui.List;

	 private rank_top:RankCell;

	 private myUrl:string;
    public constructor() {
		super();
		this.skinName = "RankSkin";
	}
	public initComponent(): void {
		super.initComponent();
		this.list.itemRenderer = RankCell;
	}

	public initListener(): void {
		super.initListener();
		
		this.addEvent(this.btn_back, egret.TouchEvent.TOUCH_TAP, this.openView, this);	
		
	}
	public onOpen(data?): void {
		super.onOpen(data);
		this.initView();
		
	}
	private initView(): void {
		this.rank_top.line.visible = false;
		var that = this;
		ShareMgr.getRankData(function(array: Array<any>){
			BK.Script.log(1, 1, '-------- ：' + array.length);
			var mine = array.shift();
			
			that.rank_top.txt_rank.text = ""+mine.rank;
			that.rank_top.txt_user_name.text = mine.nick;
			that.rank_top.txt_level.text = mine.score+"关";
			that.myUrl = mine.url;
			RES.getResByUrl(mine.url,that.onComplete,that,RES.ResourceItem.TYPE_IMAGE);

			that.list.dataProvider = new eui.ArrayCollection(array);
			that.list.validateNow();
			(<RankCell>that.list.getChildAt(array.length-1)).line.visible = false;;
		});
	}

	private onComplete():void{
		var img: egret.Texture = RES.getRes(this.myUrl);
		this.rank_top.img_header.source = img;
	}

    private openView(evt: egret.TouchEvent): void {
		let viewName: string = "";
		let layType: number = LayerType.UI;
		let data = null;
		switch (evt.currentTarget) {
			case this.btn_back:
				viewName = ViewConst.INDEXVIEW;
				data = 1;
				break;
			
		}
		if (viewName) {
			zysx.LayerMgr.ins.openView(viewName, data, layType);
		}
	}
}
window["RankView"] = RankView;